package com.imonsoft.sqm.service.business.ipic_system;

import com.imonsoft.common.constant.ConstantSqm;
import com.imonsoft.common.exception.SystemException;
import com.imonsoft.sqm.dao.business.ipic_system.ClaimViewDAO;
import com.imonsoft.sqm.pojo.business.ipic_system.ClaimView;
import com.imonsoft.sqm.pojo.business.ipic_system.ClaimViewExample;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;


@Service("claimViewService")
public class ClaimViewServiceImpl implements ClaimViewService {
	protected final Log logger = LogFactory.getLog(getClass());
    @Autowired
    private ClaimViewDAO claimViewDAO;


    public List<ClaimView> findClaimView(Map<String, Object> searchMap){
        ClaimViewExample example = new ClaimViewExample();
        ClaimViewExample.Criteria criteria = example.createCriteria();
        if(null!=searchMap){
            if(null!=searchMap.get("year")){
                criteria.andYearEqualTo(Integer.parseInt((String)searchMap.get("year")));
            }
            if(null!=searchMap.get("month")){
                criteria.andMonthLessThanOrEqualTo(Integer.parseInt((String)searchMap.get("month")));
            }
            if(null!=searchMap.get("type")){
                criteria.andTypeEqualTo((String)searchMap.get("type"));
            }
        }
        List<ClaimView> claimViewList=claimViewDAO.selectClaimViewByExample(example);
        return claimViewList;
    }

    @Override
    public List<ClaimView> getAmountUnqualifiedList(String type,String year,String month) {
        ClaimViewExample example = new ClaimViewExample();
        ClaimViewExample.Criteria criteria = example.createCriteria();
        if(StringUtils.isEmpty(type) || StringUtils.isEmpty(year) || StringUtils.isEmpty(month)){
            throw new SystemException(ConstantSqm.DATA_ERROR);
        }
        criteria.andTypeEqualTo(type);
        criteria.andYearEqualTo(Integer.parseInt(year));
//        criteria.andMonthLessThanOrEqualTo(Integer.parseInt(month));
        criteria.andMonthEqualTo(Integer.parseInt(month));
        return claimViewDAO.selectClaimViewByExample(example);
    }
}
